package kr.saeildamil.androidforstudy2.ch21;

import kr.saeildamil.androidforstudy2.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ShareActionProvider;
import android.widget.TextView;

public class ShareAction extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		LinearLayout layout = new LinearLayout(this);
		
		TextView mText = new TextView(this);
		mText.setText("ShareActionProvider(Test)");
		
		EditText mEdit = new EditText(this);
		mEdit.setTag("mEdit");
		
		LayoutParams params = new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		
		layout.addView(mText);
		layout.addView(mEdit);
		setContentView(layout);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.shareactionmenu, menu);
		
		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("text/plain");
		intent.putExtra(Intent.EXTRA_TEXT, "Sharing Text");
		
		MenuItem share = menu.findItem(R.id.share);
		ShareActionProvider provider = (ShareActionProvider) share.getActionProvider();
		provider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
		provider.setShareIntent(intent);
		
		MenuItem sharemenu = menu.findItem(R.id.share);
		ShareActionProvider providermenu = (ShareActionProvider) share.getActionProvider();
		providermenu.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
		providermenu.setShareIntent(intent);
		
		return true;
	}
	
}
